using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Practices.WizardFramework;
using System.ComponentModel.Design;
using EnvDTE;
using System.IO;

namespace SPALM.SharePointSoftwareFactory.Library.CustomWizardPages
{
    /// <summary>
    /// Example of a class that is a custom wizard page
    /// </summary>
    public partial class TemplateTypeSelectionPage : SPSFBaseWizardPage
    {
        

        public TemplateTypeSelectionPage(WizardForm parent)
            : base(parent)
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

                    
        }

        public override void BeginInit()
        {
            base.BeginInit();

            SetValues();
        }

        private void CheckVisibility()
        {
            if (!HasBeenActivated)
            {
                DTE dte = GetService(typeof(DTE)) as DTE;

                //template selection is not possible in
                //vs 2008
                if (!dte.Version.StartsWith("10."))
                {
                    radioButton_Hive.Checked = true;
                    radioButton_VSeWSS.Checked = false;
                    radioButton_VSeWSS.Enabled = false;
                    label3.Enabled = false;
                    pictureBox2.Enabled = false;
                }
            }

        }

        public override bool OnActivate()
        {
            base.OnActivate();
            CheckVisibility();   
            AddBrandingPanel();
            HasBeenActivated = true;
            return true;
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            this.radioButton_VSeWSS.Checked = true;
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.radioButton_Hive.Checked = true;
        }

        private void radioButton_VSeWSS_CheckedChanged(object sender, EventArgs e)
        {
            SetValues();
        }

        private void SetValues()
        {
            try
            {
                IDictionaryService dictionaryService = GetService(typeof(IDictionaryService)) as IDictionaryService;
                dictionaryService.SetValue("IsVSEWSSTemplate", radioButton_VSeWSS.Checked);
                dictionaryService.SetValue("IsHIVETemplate", radioButton_Hive.Checked);
            }
            catch { }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string pathToHelpPage = Path.Combine(GetBasePath(), @"Help\OutputHTML\SPSF_OVERVIEW_600_ProjectTypes.html");
            if(File.Exists(pathToHelpPage))
            {
                DTE dte = GetService(typeof(DTE)) as DTE;
                Helpers.OpenWebPage(dte, pathToHelpPage);
            }
        }
    }
}